﻿using FluentResourceMapping.AutoMapping;
using FluentResourceMapping.Tests.TestDummies;
using Moq;
using NUnit.Framework;

// ReSharper disable InconsistentNaming

namespace FluentResourceMapping.Tests
{
    [TestFixture]
    public class FluentConfigurationTests
    {
        [Test]
        public void Configure_Returns_Configuration()
        {
            // Act
            var result = Fluently.Configure();

            // Assert
            Assert.IsNotNull(result);
        }

        [Test]
        public void Can_Add_Fluent_Mapping()
        {
            // Arrange       
            var mock = new Mock<ResourceMappingModel>();
            var config = Fluently.Configure(mock.Object);

            // Act 
            config.Mappings(o => o.TypeResourceMappings.Add(typeof (TestClassMap)))
                .BuildResourceMappingModel();

            // Assert
            mock.Verify(o => o.AddMapping(typeof (TestClassMap)));
        }

        [Test]
        public void Can_Create_Map()
        {
            // Act
            new TestClassMap();
        }

        [Test]
        public void Can_Add_AutoMap()
        {
            // Arrange       
            var mock = new Mock<ResourceMappingModel>();
            var config = Fluently.Configure(mock.Object);

            // Act
            config.Mappings(m => m.AutoResourceMappings.Add(AutoMap.AssemblyOf<TestClassMap>()))
                .BuildResourceMappingModel();

            // Assert
            mock.Verify(o => o.AddMapping(It.IsAny<AutoResourceMappingModel>()));
        }

        [Test]
        public void Can_Merge_Mapping()
        {
            // Arrange - Create mappings by hand
            TypeResourceMapping mapping = new TypeResourceMapping(typeof (TestClass));
            mapping.MemberResourceMappings.Add(new MemberResourceMapping(typeof (TestClass).GetMember("Name")[0],
                                                                         typeof (TestResource), "NameRes"));

            TypeResourceMapping otherMapping = new TypeResourceMapping(typeof (TestClassBase));
            otherMapping.MemberResourceMappings.Add(
                new MemberResourceMapping(typeof (TestClassBase).GetMember("BaseProperty")[0], typeof (TestBaseResource),
                                          "BaseProtertyDescription"));

            // Act
            //TODO: Continue here
            //mapping.M

            // Assert
        }
    }
}

// ReSharper restore InconsistentNaming